#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 9;
int n, a[maxn], b[maxn];
void solve() {
    long long ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    sort(a, a + n);
    sort(b, b + n, greater<int>());
    for (int i = 0; i < n; i++) {
        ans += 1ll * a[i] * b[i];
    }
    printf("%lld\n", ans);
}
int main() {
    int t;
    cin >> t;
    while (t--) solve();
}